commandsChars = {
"U": "+y",
"D": "-y",
"R": "+x",
"L": "-x"
}
countOfCommands = int(input())
commandsString = input()
commands = []
class Robot():
def __init__(self) -> None:
self.x = 0
self.y = 0
def Move(self, coord: str):
if coord == "+x":
self.x += 1
elif coord == "-x":
self.x -= 1
elif coord == "+y":
self.y += 1
else:
self.y -= 1
def isInZeroZero(self):
if self.x == 0 and self.y == 0:
return True
else:
return False
def Restart(self):
self.x = 0
self.y = 0
class Vault():
def __init__(self) -> None:
self.paths = []
def Add(self, path: list):
self.paths.append(path)
robot = Robot()
pathsVault = Vault()
for command in commandsString:
commands.append(commandsChars[command])
for firstElementIndex in range(0, countOfCommands):
for secondElement in range(firstElementIndex, countOfCommands):
secondElementIndex = countOfCommands - secondElement - 1
nowCommands = commands[firstElementIndex:secondElement + 1]
if len(nowCommands) > 1:
for element in nowCommands:
robot.Move(element)
if robot.isInZeroZero() == True:
pathsVault.Add(element)
robot.Restart()
for firstElementIndex in range(0, countOfCommands):
for secondElementIndex in range(firstElementIndex, countOfCommands):
nowCommands = command[firstElementIndex:secondElementIndex]
if len(nowCommands) > 1:
for element in nowCommands:
robot.Move(element)
if robot.isInZeroZero() == True:
pathsVault.Add(element)
robot.Restart()
print(len(pathsVault.paths))
129A - Cookies | 1367B - Even Array |
136A - Presents | 1450A - Avoid Trygub |
327A - Flipping Game | 411A - Password Check |
1520C - Not Adjacent Matrix | 1538B - Friends and Candies |
580A - Kefa and First Steps | 1038B - Non-Coprime Partition |
43A - Football | 50A - Domino piling |
479A - Expression | 1480A - Yet Another String Game |
1216C - White Sheet | 1648A - Weird Sum |
427A - Police Recruits | 535A - Tavas and Nafas |
581A - Vasya the Hipster | 1537B - Bad Boy |
1406B - Maximum Product | 507B - Amr and Pins |
379A - New Year Candles | 1154A - Restoring Three Numbers |
750A - New Year and Hurry | 705A - Hulk |
492B - Vanya and Lanterns | 1374C - Move Brackets |
1476A - K-divisible Sum | 1333A - Little Artem |